<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html  class="x-admin-sm">
<head>
	<meta charset="UTF-8">
	<title>后台登录-X-admin2.2</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="./static/css/font.css">
    <link rel="stylesheet" href="./static/css/login.css">
	  <link rel="stylesheet" href="./static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        function checkForm() {
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            if (username == null || username == "") {
                document.getElementById("error").innerHTML = "用户名不能为空";
                return false;
            }
            if (password == null || password == "") {
                document.getElementById("error").innerHTML = "密码不能为空";
                return false;
            }
            return true;
        }
    </script>

</head>
<body class="login-bg">

    <div class="login layui-anim layui-anim-up">
        <div class="message">admin1.0-管理登录</div>
        <div id="darkbannerwrap"></div>

        <form method="post" class="layui-form"  action="/login" >
            <input id="username" name="username" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <input id="password" name="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">

            <input id="rememberMe" name="rememberMe" type="checkbox">记住我  <font id="error" color="red"></font>

            <hr class="hr25">
            <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
        </form>
    </div>


</body>
<script type="text/javascript">

    var form = document.querySelector("form");


    // 重写表单提交事件，让方法返回值为false，禁止表单提交
    form.onsubmit = function () {
        var username = $("#username").val();
        var password = $("#password").val();
        var rememberMe = $("input[type='checkbox']").is(':checked'); //jQuery获取复选框的值，选中为true，不选为false
        console.log(rememberMe);

        loginByPOST(username, password, rememberMe);
        return false;
    };

    function loginByPOST(username, password, rememberMe) {
        console.log("rememberMe：" + rememberMe + ", username：" + username + ", password：" + password);
        var url = "login";
        $.ajax(url, {
            type:"GET",
            data:{
                username:username,
                password:password,
                rememberMe:rememberMe
            },
            dataType:"json",
            success:function (data, textStatus, jqXhr) {
                console.log(data);
                console.log("data的类型：" + (typeof data));
                console.log(textStatus);
                $("#error").text(data.message);

                // var location = data.data; // 跳转的地址
                var location = "http://localhost:8080/" + data.data;
                console.log(location);
                // alert(location);

                // var errorMsg = data.code;
                if (data.code == 200) {
                    document.location.href = location;
                }

            }
        });
    }

</script>

</html>